<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.meila.cms.entity.User"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

User u=((User) session.getAttribute("loginUser"));
%>

<!DOCTYPE HTML>
<html lang="zh-CN">
  <head>
    <base href="<%=basePath%>">
    
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <title>账户设置</title>
    
    <jsp:include page="../common/common.jsp"></jsp:include>
    
    
  </head>
  
  <body class="client-body baseContent-active">
  	<jsp:include page="../common/client-head.jsp"></jsp:include>
	<script src="<%=request.getContextPath() %>/resources/js/system/index/jquery.md5.js"></script>
	<script src="<%=request.getContextPath() %>/resources/js/ajaxfileupload.js"></script>
	<script src="<%=request.getContextPath() %>/resources/js/My97DatePicker/WdatePicker.js"></script>
	<script src="<%=request.getContextPath() %>/resources/js/system/account/accountSet.js"></script>
    
  	<div class="client-content">
  		<jsp:include page="../common/client-leftMenu-setting.jsp"></jsp:include>
  	
  		<div class="client-contentBox">
  			<div id="as-title" class="as-title clearfix">
  				<a id="" data-page="baseContent" class="a-black baseBtn" href="front/setting/accountSet">基本资料</a>
  				<a id="" data-page="approveContent" class="a-black approveBtn" href="front/setting/approveContent">认证资料</a>
  				<a id="" data-page="updatePassContent" class="a-black updatePassBtn" href="front/setting/updatePassContent">修改密码</a>
  			</div>
  		
  			<!-- 基本资料 -->
  			<form id="baseContent" class="form-horizontal as-formBox as-formBox2" style="display: block;">
			  <div class="form-group">
			    <label class="col-sm-3 control-label">手机</label>
			    <div class="col-sm-9">
			    	已绑定手机号：<span id="tel">${user.phone}</span>
			    	<input type="hidden" id="type" value="${user.type}">
			    	<input type="hidden" id="phone" value="${user.phone}">
			    	<input type="hidden" id="xingbie" value="${user.sex}">
			    	<input type="hidden" id="shengfen" value="${user.province}">
			    	<input type="hidden" id="chengshi" value="${user.city}">
			    	<a class="btn btn2 a-white as-formStyle" href="javascript:;" style="display: none">更换</a>
			    </div>
			  </div>
			  
			  <div class="form-group">
			    <label class="col-sm-3 control-label">性别</label>
			    <div class="col-sm-9 as-formStyle2">
			    	  男<input id="radio1" type="radio" name="sex" value="2" checked="checked" />
			    	  女<input id="radio2" type="radio" name="sex" value="1" />
			    </div>
			  </div>
			  
			  <div class="form-group">
			    <label class="col-sm-3 control-label">所在地</label>
			    <div class="col-sm-9 as-formStyle2">
			    	<select id="province" name="province" style="width:140px">
						<option>浙江省</option>
						<option>江苏省</option>
					</select>
			    	<select id="city" name="city" style="width:130px">
			    		<option value=''>---请选择---</option>
					</select>
			    </div>
			  </div>
			  
			  <div class="form-group">
			    <div class="col-sm-offset-3 col-sm-9">
			      <button type="submit" id="save" class="btn btn2 a-white as-formStyle3">保存</button>
			    </div>
			  </div>
			  
			  <div id="error1" class="error-resgister">
					<span id="errorContent1"></span><!-- 错误提示 -->
			  </div>
			</form>
			
  		</div><!-- as-content -->
  	</div><!-- client-content -->
	
  	<script type="text/javascript">
		/* function contentToggle(){
			var tabItems = $("#as-title a");
	        tabItems.each(function() {
	            $(this).click(function(e) {
	                var page = $(this).data("page");
	                setCurrentPage(page);
	                
	                e.preventDefault();
	                return false;
	            });
	        });
		}
		
		var curPage = "baseContent";
		
		function setCurrentPage(newPage) {
			var $body = $(document.body);
	        if (newPage != curPage) {
	            $body.removeClass(curPage + '-active');
	            $body.addClass(newPage + '-active');
	            
				$("#" + curPage).hide();
	            $("#" + newPage).show();
	            
	            curPage = newPage;
	        }
	    } */
	    
	    function addWork(){
	    	$("#as-workAdd").click(function(){
	  			var node=document.getElementById("as-workBar");
	    		
				var areaBar=node.cloneNode(true);
				areaBar = $(areaBar);
 					
 				var areaInput = areaBar.find("input");
 				areaInput.attr("name", "work");//请根据需要重新设置
 				
				$("#as-works").append(areaBar);
				
	    	});
	    }
	    
	    function saveBaseInfo(){
	    	$("#save").click(function(){
	    		var city=$("select[name='city']").val();
	    		var province=$("select[name='province']").val();
	    		
	    		if(city==""||province==""){
	    			$("#error1").css("display","block");
					$("#errorContent1").text("请选择城市！");
					return false;
	    		}else{
	    			$("#errorContent1").text("");
	    			$.ajax({
	    				type:'post',
	    				url:CONTEXT_PATH+'front/setting/saveBaseInfo?phone='+$("#phone").val(),
	    				data: $("#baseContent").serialize(),
	    				async: false,
	    				success:function(data){
	    					if(data.flag){
	    						alert("保存成功！");
	    					}else{
	    						alert("保存失败！");
	    					}
	    				}
	    			});
	    		}
	    	});
	    }
	    
	    function updatePwd(){
	    	$("#update").click(function(){
	    		var oldpassword=$("#oldpassword").val();
	    		var newpassword=$("#newpassword").val();
	    		var checkpassword=$("#checkpassword").val();
	    		
	    		var pwd=/(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^.{6,16}$/;  //6~16位字符，至少包含数字.字母.符号中的2种
	    		
	    		if(oldpassword=="" || newpassword=="" || checkpassword==""){
	    			$("#error3").css("display","block");
					$("#errorContent3").text("您所填信息不完整！");
	    		}else if(!pwd.test(newpassword)){
	    			$("#error3").css("display","block");
					$("#errorContent3").text("密码必须是6-16位，至少包含数字.字母.符号中的2种！");
	    		}else if(newpassword==oldpassword){
	    			$("#error3").css("display","block");
					$("#errorContent3").text("新旧密码不能相同！");
	    		}else if(checkpassword!=newpassword){
	    			$("#error3").css("display","block");
					$("#errorContent3").text("您两次输入的密码不一致！");
	    		}else{
	    			$("#errorContent3").text("");
	    			upPwd();	
	    		}
	    	});
	    }
	    
	    function upPwd(){
	    	$.ajax({
	    		type:'post',
	    		url:CONTEXT_PATH+'front/setting/updatePwd',/* +$("#phone").val() */
	    		data: {"phone":$("#phoneno").val(),"opassword":$.md5($("#oldpassword").val()),"npassword":$.md5($("#newpassword").val())},
	    		async: false,
	    		success:function(data){
					if(data.flag){
						alert(data.message);
					}else{
						alert(data.message);
					}
	    		}
	    	});
	    }
	    
	    function submitConfirm(){//个人认证
	    	$("#personalsubmit").click(function(){
	    		var name=$("#name").val();
	    		var company=$("#company").val();
	    		var addr=$("#studioaddr").val;
	    		var card=$("#iddiv").html();
	    		var idcardf=$("#idfdiv").html();
	    		var idcardo=$("#idodiv").html();
	    		var works1=$("#works1").val();
	    		var works2=$("#works2").val();
	    		var works3=$("#works3").val();
	    		
	    		var re=/^.{5,}$/;
	    		var re1=/^.{0,20}$/;
	    		
	    		if(name==""||company==""||addr==""||/^\s*?$/.test(card)){//身份证正反面为选填项？||/^\s*?$/.test(idcardf)||/^\s*?$/.test(idcardo)
	    			$("#error2").css("display","block");
					$("#errorContent2").text("您所填信息不完整！");
	    		}else if(!re.test(company)||!re.test(addr)){
	    			$("#error2").css("display","block");
					$("#errorContent2").text("公司/个人工作室及办公地址不少于5个汉字！");
					alert("公司/个人工作室及办公地址不少于5个汉字！");
	    		/* }else if(!re1.test(works1)||!re1.test(works2)||!re1.test(works3)){//个人作品为选填项？
	    			$("#error2").css("display","block");
					$("#errorContent2").text("个人作品每条不大于20个汉字！");
					alert("个人作品每条不大于20个汉字！"); */
	    		}else{
	    			$("#errorContent2").text("");
	    			$.ajax({
	    				type:'post',
	    				url:CONTEXT_PATH+'front/setting/personalConfirm?phone='+$("#phone").val(),
	    				data:$("#personalData").serialize(),
	    				async: false,
	    				success:function(data){
	    					if(data.flag){
	    						alert(data.message);
	    					}else{
	    						alert(data.message);
	    					}
	    				}
	    			});
	    		}
	    	});
	    }
	    
	    function firmSubmit(){//公司认证
	    	$("#firmsubmit").click(function(){
	    		var name=$("#firmname").val();
	    		var site=$("#firmaddr").val();
	    		var contacts=$("#contacts").val();
	    		var fixedtel=$("#fixedtel").val();
	    		var establishmentDate=$("#establishmentDate").val();
	    		var scale=$("#scale").val();
	    		var licensediv=$("#licensediv").html();//营业执照
	    		
	    		
	    		var re=/^.{4,}$/;
	    		
	    		if(name==""||site==""||contacts==""||fixedtel==""||establishmentDate==""||scale==""||/^\s*?$/.test(licensediv)){
	    			$("#error2").css("display","block");
					$("#errorContent2").text("您所填信息不完整！");
	    		}else if(!re.test(name)||!re.test(site)){
	    			$("#error2").css("display","block");
					$("#errorContent2").text("公司名称及公司地址不少于5个汉字！");
	    		}else{
	    			$("#errorContent2").text("");
	    			$.ajax({
	    				type:'post',
	    				url:CONTEXT_PATH+'front/setting/firmConfirm?phone='+$("#phone").val(),
	    				data:$("#firmData").serialize(),
	    				async: false,
	    				success:function(data){
	    					if(data.flag){
	    						alert(data.message);
	    					}else{
	    						alert(data.message);
	    					}
	    				}
	    			});
	    		}
	    	});
	    }
	    
	    if('${userModel.license}'){
            fileid='${userModel.license}'.split(",");
            setimg(fileid,'iddiv');
        }else{
            fileid=[];
        }
	    
	    var uploadFile = function(type,id,div,error,phone) {
	    	if ($("#"+id).val() == "") {
				alert("请选择一个附件!");
				return;
			}else{
				var file=$("#"+id).val();
				var fileType = file.substring(file.lastIndexOf(".") + 1);
				if (!(fileType && /^(jpg|JPG|png|PNG|bmp|BMP|gif|GIF)$/.test(fileType))){
					$("#"+error).css('display', 'block');
					return;
				}else{
					$("#"+error).css('display', 'none');
					fileid=[];
					$.ajax({
						type:"post",
						async : false,
						url : FILESERVER_ID,
						dataType : "jsonp",
						jsonp : 'jsonpcallback',// 传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
						jsonpCallback : "feedBackState",// 自定义的jsonp回调函数名称，默认为jQuery自动生成的随机函数名
						success : function(data) {
							fileid.push(data[0].id);
							
							$.ajaxFileUpload({
								url : FILESERVER_UPLOAD_PATH + '?origin=A3&id=' + data[0].id +'&note='+phone,
								secureuri : false,// 一般设置为false
								fileElementId : id,// 文件上传空间的id属性 <input
													// type="file" id="file"
													// name="file" />
								dataType : 'jsonp',// 返回值类型 一般设置为json
								jsonp : 'jsoncallback',
								success : function(data, status) // 服务器成功响应处理函数
								{
									setimg(fileid, div);
								},
								error : function(data, status, e)// 服务器响应失败处理函数
								{
									setimg(fileid, div);
								}
							});
						},
						error : function() {
						}
					});
				}
			}
			$("#"+id).val("");
	    };
	    
	    var setimg = function(id, element) {
	    	$("#" + element).html("");
	    	for ( var i = 0; i < id.length; i++) {
	    		if (id[i] != '') {
	    			if(element=='iddiv'){
	    				$("#" + element)
							.append(
									"<div class='images'>"
									+ "<div class='imgbox'><span>"
									+ "<img   onclick='javascript:parent.openImg(\""
									+ FILESERVER_PATH
									+ "\",\""
									+ id[i]
									+ "\")' src=\""
									+ FILESERVER_PATH
									+ "?id="
									+ id[i]
									+ "\"/><input type='hidden' id='license' name='license' value='"
									+ id[i]
									+ "'></span>"
									+ "</div>");
	    			}else if(element=='idfdiv'){
	    				$("#" + element)
							.append(
									"<div class='images'>"
									+ "<div class='imgbox'><span>"
									+ "<img   onclick='javascript:parent.openImg(\""
									+ FILESERVER_PATH
									+ "\",\""
									+ id[i]
									+ "\")' src=\""
									+ FILESERVER_PATH
									+ "?id="
									+ id[i]
									+ "\"/><input type='hidden' id='idfront' name='idfront' value='"
									+ id[i]
									+ "'></span>"
									+ "</div>");
	    			}else if(element=='idodiv'){
	    				$("#" + element)
							.append(
									"<div class='images'>"
									+ "<div class='imgbox'><span>"
									+ "<img   onclick='javascript:parent.openImg(\""
									+ FILESERVER_PATH
									+ "\",\""
									+ id[i]
									+ "\")' src=\""
									+ FILESERVER_PATH
									+ "?id="
									+ id[i]
									+ "\"/><input type='hidden' id='idopposite' name='idopposite' value='"
									+ id[i]
									+ "'></span>"
									+ "</div>");
	    			}else if(element=='licensediv'){
	    				$("#" + element)
							.append(
									"<div class='images'>"
									+ "<div class='imgbox'><span>"
									+ "<img   onclick='javascript:parent.openImg(\""
									+ FILESERVER_PATH
									+ "\",\""
									+ id[i]
									+ "\")' src=\""
									+ FILESERVER_PATH
									+ "?id="
									+ id[i]
									+ "\"/><input type='hidden' id='license' name='license' value='"
									+ id[i]
									+ "'></span>"
									+ "</div>");
	    			}	    			
	    		}
	    	}
	    };
	</script>
	
  </body>
</html>
